package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "自媒体用户API",tags = "自媒体用户API")
@RestController
@RequestMapping("/api/v1/user")
public class WmUserController {

    @Autowired
    private WmUserService wmUserService;

    /*
     * todo 根据名称查询自媒体用户信息
     *  */
    @ApiOperation("根据名称查询自媒体用户信息 ")
    @GetMapping("/findByName/{name}")
    public ResponseResult<WmUser> queueUserByName(@PathVariable("name") String name){
        //todo 创建条件查询构造器
        LambdaQueryWrapper<WmUser> lambdaQuery = Wrappers.lambdaQuery();
        //todo 根据条件查询
        LambdaQueryWrapper<WmUser> wUser = lambdaQuery.eq(WmUser::getName, name);
        WmUser wmUser = this.wmUserService.getOne(wUser);
        return ResponseResult.okResult(wmUser);
    }

    /*
    TODO  保存自媒体用户信息
     */
    @ApiOperation("保存自媒体用户信息")
    @PostMapping("/save")
    public ResponseResult<WmUser> saveVmUser(@RequestBody WmUser wmUser){
        this.wmUserService.save(wmUser);
        return ResponseResult.okResult(wmUser);
    }




}
